<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">
        点我
    </button>

    <script>
        
        /*js是单线程的运行的，会先将直接输出定义循环的先执行之后再执行函数里面的东西*/
        window.addEventListener('load',function(){
            let btn = document.getElementById('btn'),timer=null;

            btn.addEventListener('click',function(){
                clearInterval(timer);
                let cur =Date.now();
                console.log('-------之前------')

                timer = setInterval(function(){
                    console.log(Date.now()-cur + 'ms之后执行');
                },1000)
                console.log('-------之后------')

                //耗时操作
                for(let i=0;i<1000000000;i++){
                    console.log(i++)
                }
            })
        })
    </script>
</body>
</html>